<template>
  <!-- 订单管理页面 -->
  <div>

    <!-- 条件筛选 -->
    <el-row :gutter="24">
      <el-col :span="24">
        <el-card shadow="always">
          <el-form :inline="true" :model="queryForm" ref="queryForm" class="demo-form-inline">
            <el-form-item label="订单号" prop="orderNum">
              <el-input v-model="queryForm.orderNum" placeholder="订单号"></el-input>
            </el-form-item>
            <el-form-item label="订单状态" prop="orderStatus">
              <el-select v-model="queryForm.orderStatus" placeholder="订单状态">
                <el-option label="待支付" value=0></el-option>
                <el-option label="已支付" value=1></el-option>
                <el-option label="待发货" value=2></el-option>
                <el-option label="待收货" value=3></el-option>
                <el-option label="已签收" value=4></el-option>
                <el-option label="已关闭" value=5></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="订单来源" prop="orderSource">
              <el-select v-model="queryForm.orderSource" placeholder="订单来源">
                <el-option label="线下" value=0></el-option>
                <el-option label="线上" value=1></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="支付方式" prop="payType">
              <el-select v-model="queryForm.payType" placeholder="支付方式">
                <el-option label="现金" value=0></el-option>
                <el-option label="微信" value=1></el-option>
                <el-option label="支付宝" value=2></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="warning" @click="resetForm('queryForm')">重置</el-button>
              <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>

    <br>

    <!-- 按钮操作 -->
    <el-row :gutter="24">
      <el-col :span="24">
        <el-card shadow="always" style="text-align: left">
          <el-button type="success" size="small" @click="exportData">导出查询结果</el-button>
        </el-card>
      </el-col>
    </el-row>

    <br>

    <!-- 数据列表 -->
    <el-row :gutter="24">
      <el-col :span="24">
        <el-card shadow="always">
          <el-table :data="tableData" border style="width: 100%" @sort-change="sortChange">
            <el-table-column type="selection" width="50"></el-table-column>
            <el-table-column prop="orderNum" label="订单号" width="234" sortable="custom"></el-table-column>
            <el-table-column prop="orderStatus" label="订单状态" sortable="custom">
              <template slot-scope="scope">
                <span>{{ scope.row.orderStatus === 0?'待支付' :'已支付'}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="orderSource" label="订单来源">
              <template slot-scope="scope">
                <span>{{ scope.row.orderSource === 0?'线下' :'线上'}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="orderPrice" label="订单金额"></el-table-column>
            <el-table-column prop="payType" label="支付方式">
              <template slot-scope="scope">
                <span v-if="scope.row.payType === 0">现金</span>
                <span v-if="scope.row.payType === 1">微信</span>
                <span v-if="scope.row.payType === 2">支付宝</span>
              </template>
            </el-table-column>
            <el-table-column prop="createBy" label="收货人" width="139px"></el-table-column>
          </el-table>
          <div class="block" style="margin-top: 10px; text-align: right">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[10, 20, 30, 50]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="dataCount">
            </el-pagination>
          </div>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script>

  import {post} from '@/api/http.js'

  export default {
    name: "order",
    // 页面加载就执行
    mounted: function () {
      this.getListData();
    },

    // 双向数据绑定
    data() {
      return {
        // 表单数据邦迪
        queryForm: {
          orderNum: '',
          orderStatus: null,
          orderSource: null,
          payType: null,
          current: 0,
          size: 10,
          sortBy: '',
          sortOrder: ''
        },

        // 表格数据
        tableData: [],

        // 分页参数
        currentPage: 1,
        pageSize: 10,
        dataCount: 0,

      }
    },

    // 方法区
    methods: {

      // 表格排序
      sortChange(column) {
        this.queryForm.sortBy = column.prop;
        this.queryForm.sortOrder = column.order;
        this.getListData();
      },

      // 导出Excel
      exportData() {
        this.$message({
          type: 'success',
          message: '导出成功'
        });
      },

      // 提交查询表单
      onSubmit() {
        this.getListData();
      },

      // 重置查询表单
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },

      // 分页组件参数变动
      handleSizeChange(val) {
        this.queryForm.size = val;
        this.getListData();
      },
      handleCurrentChange(val) {
        this.queryForm.current = val;
        this.getListData();
      },

      // 获取列表数据
      getListData() {
        post("/order/list", this.queryForm)
          .then(res => {
            this.tableData = res.data.records;
            this.dataCount = res.data.total;
            this.pageSize = res.data.size;
            this.currentPage = res.data.current;
          })
          .catch(err => {
          })
          .finally(() => {
          })
      }
    }
  }
</script>

<style scoped>

</style>
